﻿using UnityEngine;
using System.Collections;

namespace UI
{
    public class UIUnionFightReviveTips : MonoBehaviour
    {
        public UILabel timeTip;
        public UILabel content;
        float maxTime, curTime;
        string timerTipStr;
        UIUnionFightBagItem script;
        bool isDead;
        public void Init(float time, GameObject item = null)
        {
            if(item != null)
            {
                script = item.GetComponent<UIUnionFightBagItem>();
                content.text = string.Format(TableTextBlo.GetText("union_fight_revive_tips"),script.restNum.text);
            }
            gameObject.SetActive(true);
            curTime = time;
            timerTipStr = TableTextBlo.GetText("field_pvp_easter_timer");
            GetComponent<PageTweener>().Play();
            isDead = true;
        }

        void Update()
        {
            curTime -= Time.deltaTime;
            if(curTime <= 0 && isDead)
            {
                isDead = false;
                gameObject.SetActive(false);
            }
            else
            {
                timeTip.text = string.Format(timerTipStr, (int)(curTime));
            }
        }

        //使用复活道具立即复活，数据待填
        public void OkBtn()
        {
            script.OnClickItem();
            //去掉复活时间计时==
            GetComponentInParent<UIUnionFightRunMap>().SetReviveTime(0);
            gameObject.SetActive(false);
        }

        public void Cancel()
        {
            gameObject.SetActive(false);
        }
    }
}
